<template>
  <div>
    <!--新增或者编辑的弹出框-->
    <el-dialog :title="formTitle" :visible.sync="dialogFormVisible" :close-on-click-modal = "false" width="40%">
      <el-form class="form" :model="modelForm" :rules="rules" ref="modelForm" style="text-align: center">
        <el-form-item label="部门名称" :label-width="formLabelWidth" align="left" prop="dname">
          <el-input v-model="modelForm.dname" autocomplete="off" :style="style"></el-input>
        </el-form-item>
        <div style="text-align: center">
          <el-button type="primary" @click="addOrEditData">确 定</el-button>
          <el-button @click="dialogFormVisible = false">取 消</el-button>
        </div>
      </el-form>
    </el-dialog>
  </div>
</template>

<script>
    import modelMixin from '@/mixins/modelMixin'

    export default {
        name: "DeptModel",
        mixins: [modelMixin],
        data() {
            return {
                //表单标题
                title: "部门信息",
                //表单数据
                modelForm: {
                    deptno: null,
                    dname: null
                },
                //验证规则
                rules: {
                    //部门名称不能为空
                    dname: [
                        {required: true, message: '请输入部门名称',trigger: 'blur'}
                    ]
                },
                //后台接口路径
                url: {
                    addData: 'addDept',
                    editData: 'editDept'
                },
                //主键
                key: 'deptno'
            }
        },
        methods: {
            /**
             * 重置表单
             */
            resetModelForm() {
                this.modelForm = {
                    deptno: null,
                    dname: null
                }
            }
        }
    }
</script>

<style scoped>
  .form {
    display: flex;
    flex-direction: column;
  }
</style>